package deom13;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-04-18
 * Time: 8:27
 */
class ListNode{
    int val;
    ListNode next;
    public ListNode(int val){
        this.val = val;
    }
}

public class Test1 {
    public ListNode deleteDUplicates(ListNode head){
        if(head == null || head.next == null){
            return head;
        }
        ListNode pHead = new ListNode(-1);
        pHead.next = head;
        ListNode cur = head;
        ListNode pre = pHead;
        while (cur != null && cur.next != null){
            if(cur.val == cur.next.val){
                int tmp = cur.val;
                while (cur.next != null && cur.next.val == tmp){
                    cur = cur.next;
                }
                pre.next = cur.next;
                cur = cur.next;
            }else {
                pre = cur;
                cur = cur.next;
            }
        }
        return pHead.next;
    }
}
